﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Job.Logic.Common;
using Job.Web.Framework;
using System.Web.UI.HtmlControls;

namespace Job.Web.userControls.Public
{
    public partial class SubjectNavgate : BaseCtrl
    {
        int categoryId
        {
            get
            {
                return myR["categoryid"].IntValue;
            }
        }

        int subjectid = myR["subjectid"].IntValue;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.LoadData();

                if (categoryId == (Int32)Constants.CategoryType.Company)
                {
                    lbCategoryName.Text = "关于无忧";
                }
                else if (categoryId == (Int32)Constants.CategoryType.Hunter)
                {
                    lbCategoryName.Text = "猎头专区";
                }
                else if (categoryId == (Int32)Constants.CategoryType.Service)
                {
                    lbCategoryName.Text = "人事外包";
                }

            }
        }

        private void LoadData()
        {
            SubjectLogic logic = new SubjectLogic();
            DataTable dt = logic.GetSubjectData();
            List<BaseInfo> list = WebCommon.GetCategorySubList(categoryId.ToString());

            dlSubjectNavgage.DataSource = list;
            dlSubjectNavgage.DataBind();

        }

        protected void dlSubjectNavgage_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            ListItemType type = e.Item.ItemType;
            switch (type)
            {
                case ListItemType.Item:
                case ListItemType.AlternatingItem:
                    {
                        HtmlAnchor hunterItem = (HtmlAnchor)e.Item.FindControl("hunterItem");
                        Label lblid = (Label)e.Item.FindControl("lblid");
                        int _subjectId = Constants.GetListIdByInfoId(subjectid);
                        BaseInfo info = WebCommon.GetSubjectInfo(lblid.Text.Trim());
                        //给二级栏目设置URLLINK
                        hunterItem.HRef = WebCommon.GetApplicationPath(Request) + "Item.aspx?categoryid=" + categoryId + "&subjectid=" + lblid.Text.Trim();
                        //如果需要特殊设置则应用特殊设置的URL
                        if (!string.IsNullOrEmpty(info.LinkUrl))
                        {
                            hunterItem.HRef = WebCommon.GetApplicationPath(Request) + info.LinkUrl;
                        }
                        ////如果ID跟URL中的subectid一样则将对应的二级栏目设置成选中的CSS。
                        //if (_subjectId == Convert.ToInt32(lblid.Text.Trim()))
                        //{
                        //    hunterItem.Attributes.Add("class", "select_serviceTD");
                        //}
                        break;
                    }
            }
        }
    }
}